package com.liull.netty.cust_protocol;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

/**
 * @Author: liull
 * @Description: 自定义解码器（入站处理器）,byte转为message,也就是解码in的数据，添加至out
 * @Date: Created in 16:45 2020/11/15
 * @Modified By:
 */
public class PersonDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("PersonDecoder invoked!");
        // 协议头，表示conten长度
        int length = in.readInt();
        byte[] bytesDst = new byte[length];
        in.readBytes(bytesDst);
        PersonProtocol protocol = new PersonProtocol(length, bytesDst);
        out.add(protocol);
    }
}
